/**
 * 
 */
package etf.db40;

import etf.library.Address;

import com.db4o.ObjectContainer;

/**
 * Class for testing insert, delete, update and lookup of a simple object using
 * object oriented database db40
 * 
 * @author Nermin Softic
 */
/**
 * @author Nermin
 *
 */
/**
 * @author Nermin
 *
 */
public class LightweightTest extends UtilDb4o{
	
	final static String DB4OFILENAME = "/LightweightTest.db4o";
	//private static Runtime _runtime = Runtime.getRuntime();

	static ObjectContainer db2;
	
	private LightweightTest(){
		db2 = UtilDb4o.createDatabase(DB4OFILENAME);
	}
	private LightweightTest(String fileName){
		db2 = UtilDb4o.createDatabase("/" + fileName + ".db40");
	}
	/*
	 * Funkcija koja generise zadani broj slogova i iste
	 * insertuje u bazu podataka
	 */
	public static long testInsert(int brojSlogova) {
		long startTime = System.currentTimeMillis();
		for (int i = 0; i < brojSlogova; i++) {
			Address address1 = new Address("Splitska" + i,i, "Sarajevo", 71000, "BiH");
			db2.store(address1);
		}
		db2.commit();
		long stopTime = System.currentTimeMillis();
		long elapsedTime = stopTime - startTime;
		return elapsedTime;
	}
	 /*
	  * Funkcija koja brise zadani broj slogova
	  * Generisati slucajnu sekvencu brojeva koji predstavlju id
	  * ili neko drugo unique polje a zatim izbrisati date objekte
	  * Koriste se SODA upiti
     */
	public static long testDelete(int brojSlogova) {
		 
		
		long startTime = System.currentTimeMillis();
		
		
		long stopTime = System.currentTimeMillis();
		long elapsedTime = stopTime - startTime;
		return elapsedTime;
	}
    /*
     *  Funkcija koja brise sve elemente jedne jednostavne klase
     *  Koristi se QBE mehanizam
     */
	public static long testDeleteAll(){
		long startTime = System.currentTimeMillis();
		
		
		long stopTime = System.currentTimeMillis();
		long elapsedTime = stopTime - startTime;
		return elapsedTime;
		
	}
	
	
	
}
